package com.mall.bargain.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.common.response.CommonResponse;
import com.mall.entity.bargain.BgBargain;
import com.mall.bargain.mapper.BargainListMapper;
import com.mall.bargain.service.BargainListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 砍价列表业务处理
 * @author LiJinYang
 * @version 1.0
 * @email 283006176@qq.com
 * @date 2021/07/19 16:09
 */
@Service
public class BargainListServiceImpl implements BargainListService {
    @Autowired
    private BargainListMapper bargainListMapper;

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<BgBargain> findAll() {
        return bargainListMapper.findAll();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @param bgBargain
     * @return
     */
    @Override
    public PageInfo findPage(int page, int size, BgBargain bgBargain) {
        PageHelper.startPage(page,size);
        List<BgBargain> listMapperPage=bargainListMapper.findPage(bgBargain);
        return new PageInfo(listMapperPage);
    }

    /**
     * 根据ID逻辑删除
     * @param id
     * @return
     */
    @Override
    public CommonResponse delete(Long id) {
        Integer delete = bargainListMapper.delete(id);
        if(id==null){
            return new CommonResponse(-1, "参数不能为空");
        }
        if(delete>=1){
            return new CommonResponse(0, "操作成功");
        }else {
            return new CommonResponse(-1, "操作失败");
        }
    }
}
